All Questions
52 questions
-3votes
2answers
97views
How can find special row and replace special strings
I wrote a todo list script with "add","clear" and "find" argument. I need to pass a "done" argument and script find related row and replace its first column ...
0votes
1answer
230views
Replacing multiple substrings in a filename with one (bash or zsh)
I have a text file with filenames, where the filenames contain information in various formats (e.g., resolution 4k, 4K, 2160, XxY etc) and I want to rename files to a singular consistent format. When ...
3votes
5answers
415views
Replace empty lines in one file with lines from another file
I have file1.csv "word 1" "" "word 3" "" "word 5" "word 6" and file2.csv "replacement text 1" "replacement text 2" &...
2votes
3answers
5kviews
Replace empty string with text using sed or similar tool
Is it possible to replace an empty string with some text using sed or similar tool? sed 's/^$/sometext/' will match an empty line but that is not what I am looking for. I thought that sed 's//...
1vote
2answers
166views
sed -Extended RegEx question here
I feel dumb as a sack of hammers asking this here, but it's been a long day and I simply CANNOT figure out what I'm doing wrong here. I have a file; we'll call it textfile.txt. It's contents are (in ...
1vote
2answers
896views
sed replacing a string with itself and a new line
I have the following string multiple times in a html file <br> <h4 id=... Now, I know sed might not be perfect for html editing, but could tell me how can I replace br> <h4 id with br&...
3votes
2answers
4kviews
How to substitute non printable characters with space character in a file
I have read nearly every answer about this topic on this website or Stackoverflow but didn't manage to solve the issue below. When I copy the text from a PDF file and paste it into a text file file....
0votes
1answer
135views
How can I replace a word with another word in a whole hierarchy of files
I have a hierarchy of files and two words: word1 and word2. In this hierarchy of files, some of them can contain word1. I want to replace every occurrence of word1 with word2. It is possible using a ...
-1votes
1answer
86views
How to search and replace text in files but keep/reuse a certain part of text?
I want to refactor many JavaScript files in many directories which contain access to an object in this format: myObj.something.somethingElse and I want it to be myObj.getSomething(somethingElse) how ...
-1votes
2answers
652views
Search and replacing a string on specific file extensions with the folder name
I want to find a string ("AAA") in an specific file extension ("*.txt") inside a directory tree (../MyParentFolder), and replace it with the subfolder name (MySubfolder). I know a ...
2votes
2answers
5kviews
Alternative to sed -i that does not write temporary files
I have several scripts that edit template text files, by removing a "tag" and replacing it with e.g. a number. To do this I use the sed -i command. However, I have an issue with write/read ...
-1votes
2answers
894views
Bash, match string and then replace everything after character in next line
What I am looking to do is find a match and then replace everything after character in the next line. Example file contents: super_service: app_version: 1.02 duper_service: app_version: 4....
0votes
3answers
3kviews
Struggling using sed command with variables
So I have the following variables defined in a bash script: new_commit="back:h3912kk" old_commit="back:1.0.1" file = docker-compose.yml Then I have this yml $file: version: '...
2votes
2answers
383views
Vendor from MAC address (first three parts)
How you can get the first three parts from MAC address? $ mac=11:22:33:44:55:66 $ vendor=${${mac//:/}:0:6} bash: ${${mac//:/}:0:6}: bad substitution ${mac//:/} removes : and :0:6 should get the first ...
-1votes
1answer
53views
Replace certain strings
I've got a text file containing the following: yyyy-mm-dd, 12:34/s-show/... yyyy-mm-dd, 13:24/s-show/... yyyy-mm-dd, 14:32/s-show/... yyyy-mm-dd/s-show Now I'd like to replace the substrings before /...